<?php

namespace App\Models\Business;
use Illuminate\Database\Eloquent\Model;
use App\Models\Region as RegionModel;
class Address extends Model{
    protected $table = 'business_address';

    // 是否主动维护时间戳
    public $timestamps = false;

    protected $guarded = [];
    protected $appends = [
        'region_text', //地区
    ];
    public function getRegionTextAttribute()
    {
        $egion = '';

        $province = RegionModel::where('code', $this->attributes['province'])->value('name');

        if($province)
        {
            $egion = $province;
        }

        $city = RegionModel::where('code', $this->attributes['city'])->value('name');

        if($city)
        {
            $egion .= $city;
        }

        $district = RegionModel::where('code', $this->attributes['district'])->value('name');

        if($district)
        {
            $egion .= $district;
        }

        return $egion;
    }
}